package sapling.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sapling.dao.CompanyDao;
import sapling.form.AdminForm;
import sapling.model.Company;

import java.util.Objects;

/**
 * Created by Administrator on 2017/6/21.
 */
@Service
@Transactional
public class CompanyService {

    @Autowired
    private CompanyDao companyDao;

    /**
     * 新建公司
     * @param form
     * @return
     */
    public Company save(AdminForm form) {
        Company company=companyDao.findOneByName(form.getName());
        if(Objects.isNull(company)){
            company=new Company();
        }
        company.setName(form.getName());
        company.setAddress(form.getAddress());
        company.setEmail(form.getEmail());
        company.setPersonName(form.getPersonName());
        company.setPersonPhone(form.getPersonPhone());
        companyDao.save(company);
        return companyDao.save(company);
    }
}
